package com.jingdianjichi.auth.service.impl;

import com.alibaba.fastjson.JSON;
import com.jingdianjichi.auth.common.enums.IsDeletedFlageEnum;
import com.jingdianjichi.auth.domain.convert.AuthPermissionBOConverter;
import com.jingdianjichi.auth.domain.convert.AuthRolePermissionBOConverter;
import com.jingdianjichi.auth.domain.entity.AuthPermissionBO;
import com.jingdianjichi.auth.domain.entity.AuthRolePermissionBO;
import com.jingdianjichi.auth.infra.basic.entity.AuthPermission;
import com.jingdianjichi.auth.infra.basic.entity.AuthRolePermission;
import com.jingdianjichi.auth.infra.basic.service.AuthRolePermissionService;
import com.jingdianjichi.auth.service.AuthRolePermissionDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.security.Permission;
import java.util.LinkedList;
import java.util.List;


/**
 * 权限DomainService服务实现类
 *
 * @author makejava
 * @since 2024-04-14 23:18:26
 */
@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
@Resource
private AuthRolePermissionService authRolePermissionService;
    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRolePermissionDomainServiceImpl.add.dto:{}", JSON.toJSONString(authRolePermissionBO));
        }
        Long RoelId = authRolePermissionBO.getRoleId();
        List<AuthRolePermission> rolepermissionList = new LinkedList<>();
        authRolePermissionBO.getPermissionIdList().forEach(permissionId ->{
                AuthRolePermission authRolePermission = new AuthRolePermission();
                authRolePermission.setRoleId(RoelId);
                authRolePermission.setPermissionId(permissionId);
                authRolePermission.setIsDeleted(IsDeletedFlageEnum.UN_DELETE.getCode());
                rolepermissionList.add(authRolePermission);

        });
        int count=   authRolePermissionService.insertBatch(rolepermissionList);
 return count>0;
    }


}
